<template>
    <admin-frame>
        <header class="page-header">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>会议系统</el-breadcrumb-item>
                <el-breadcrumb-item>参会嘉宾</el-breadcrumb-item>
            </el-breadcrumb>
        </header>
        <div class="mainframe-content">
            <div class="content-block">
                <header class="table-edit-header">
                    <div class="display-flex">
                        <div class="font-16 font-bold flex">
                            <span>嘉宾列表</span>
                        </div>
                        <div class="button-item">
                            <router-link to="/meeting/guest/edit" target="_blank">
                                <el-button type="primary" size="small">添加嘉宾信息</el-button>
                            </router-link>
                        </div>
                    </div>
                </header>
                <el-table :data="items" style="width: 100%" @selection-change="handleSelectionChange">
                    <el-table-column prop="id" width="45" type="selection"></el-table-column>
                    <el-table-column label="图片" width="70">
                        <template slot-scope="scope">
                            <el-image class="w50 h50" fit="cover" :src="scope.row.image"></el-image>
                        </template>
                    </el-table-column>
                    <el-table-column prop="name" width="120" label="姓名"></el-table-column>
                    <el-table-column prop="tel" width="120" label="电话"></el-table-column>
                    <el-table-column prop="code" width="120" label="邀请码"></el-table-column>
                    <el-table-column prop="organization" label="组织单位"></el-table-column>
                    <el-table-column prop="group.title" label="分组"></el-table-column>
                    <el-table-column prop="created_at" label="添加时间" width="170"></el-table-column>
                    <el-table-column width="50" label="选项">
                        <template slot-scope="scope">
                            <router-link :to="'/meeting/guest/edit?id='+scope.row.id" target="_blank">编辑</router-link>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="table-edit-footer">
                    <el-button size="small" type="primary" :disabled="selectionIds.length===0" @click="handleDelete">
                        批量删除
                    </el-button>
                    <div class="flex"></div>
                    <el-pagination
                            background
                            layout="prev, pager, next, total"
                            :total="total"
                            :page-size="pageSize"
                            @current-change="handlePageChange"
                    >
                    </el-pagination>
                </div>
            </div>
        </div>
    </admin-frame>
</template>

<script>
    import AdminFrame from "../common/AdminFrame";

    export default {
        name: "GuestList",
        components: {
            AdminFrame
        },
        data() {
            return {
                items: [],
                guest: {},
                id: 0,
                total: 0,
                offset: 0,
                pageSize: 10,
                selectionIds: [],
                groups:[]
            }
        },
        mounted() {
            this.fetchList();
            this.$get('/admin/meeting/group/getall').then(response=>{
                this.groups = response.data.items;
            });
        },
        methods: {
            fetchList() {
                this.$get('/admin/meeting/guest/batchget', {
                    offset: this.offset
                }).then(response => {
                    const {total, items} = response.data;
                    this.total = total;
                    this.items = items;
                });
            },
            handleDelete(id) {
                var items = this.selectionIds.map((d) => d.id);
                this.$confirm('此操作将永久删除所选信息, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.$post('/admin/meeting/guest/delete', {items}).then(response => {
                        this.fetchList();
                    });
                });
            },
            handleSelectionChange(val) {
                this.selectionIds = val;
            },
            handlePageChange(page) {
                this.offset = (page - 1) * this.pageSize;
                this.fetchList();
            },
        }
    }
</script>

<style scoped>

</style>
